<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta name="ctx" th:content="${#httpServletRequest.getContextPath()}"/>
    <title>广告管理</title>
    <link rel="stylesheet" th:href="@{/css/admin/base-v2.css}">
    <link rel="stylesheet" th:href="@{/lib/font-awesome/4.7.0/css/font-awesome.min.css}">
    <link rel="stylesheet" th:href="@{/css/admin/app.css}">
    <style>
        .popup-conent .section{
            max-width: 650px;
        }
        .form-item.row .label {
            width: 120px;
        }
    </style>
</head>

<body>

<div class="app-page">

    <div class="app-page-content">

        <div class="app-card">
            <div class="app-card-body">
                <div class="app-card-body-con">
                    <!-- 过滤器 -->
                    <form class="filter">
                        <div class="filter-group">
                            <div class="filter-item">
                                <div class="form-item row">
                                    <div class="label"><label>广告主</label></div>
                                    <div class="flex1">
                                        <input type="text" id="advertiserNameQuery" placeholder="广告主" name="advertiserName" th:value="${advertiserName}">
                                    </div>
                                </div>
                            </div>
                            <div class="filter-item">
                                <div class="form-item row">
                                    <div class="label"><label>广告状态</label></div>
                                    <div class="flex1">
                                        <select id="advertisementStatusQuery" name="advertisementStatus">
                                            <option value="">---请选择---</option>
                                            <option  th:each="advertisementStatus: ${advertisementStatusMap}" th:value="${advertisementStatus.key}" th:text="${advertisementStatus.value}"/>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="filter-item">
                                <div class="form-item row">
                                    <div class="label"><label>选择性别</label></div>
                                    <div class="flex1">
                                        <select id="sexQuery" name="sex">
                                            <option value="">---请选择---</option>
                                            <option th:each="sexs: ${sexMap}" th:value="${sexs.key}" th:text="${sexs.value}"/>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="filter-item">
                                <div class="form-item row">
                                    <div class="label"><label>广告名称</label></div>
                                    <div class="flex1">
                                        <input type="text" id="advertisementNameQuery" placeholder="广告名称" name="advertisementName" th:value="${advertisementName}">
                                    </div>
                                </div>
                            </div>
                            <div class="filter-item">
                                <div class="form-item row">
                                    <div class="label"><label>选择年龄</label></div>
                                    <div class="flex1">
                                        <select id="ageQuery" name="age">
                                            <option value="">---请选择---</option>
                                            <option th:each="ageRange: ${ageRangeList}" th:value="${ageRange}" th:selected="(${ageRange} == ${age})" th:text="${ageRange}"/>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div style="display: none">
                                <input name="pageNum" value="1">
                                <input name="pageSize" th:value="${pageSize}">
                            </div>
                            <div class="filter-item">
                                <button class="z-btn z-primary">查询</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="app-card">
            <div class="app-card-body">
                <div class="app-card-body-con">

                    <div class="z-btn-group">
                        <a data-title="创建部门" class="j-btn-control z-btn z-default btn-add">新增广告</a>
                    </div>

                    <table class="z-table">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>广告名称</th>
                            <th>广告品牌</th>
                            <th>广告主</th>
                            <th>是否品宣广告</th>
                            <th>年龄</th>
                            <th>性别</th>
                            <th>上屏素材</th>
                            <th>下屏素材</th>
                            <th>广告状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="advertisement: ${advertisementList}" th:attr="data-id=${advertisement.advertisementId}, data-advertisementname=${advertisement.advertisementName},data-advertisementbrand=${advertisement.advertisementBrand},
                        data-advertiserid=${advertisement.advertiserId},data-advertisername=${advertisement.advertiserName},data-age=${advertisement.age},data-sex=${advertisement.sex},data-topvideourl=${advertisement.topVideoURL},
                        data-videoname=${advertisement.videoName},data-bottomimageurl=${advertisement.bottomImageURL},data-imagename=${advertisement.imageName},data-declaregoodsadvertisement=${advertisement.declareGoodsAdvertisement},data-advertisementStatus=${advertisement.advertisementStatus}">
                            <td th:text="${advertisement.advertisementId}"></td>
                            <td th:text="${advertisement.advertisementName}"></td>
                            <td th:text="${advertisement.advertisementBrand}"></td>
                            <td th:text="${advertisement.advertiserName}"></td>
                            <div th:switch="${advertisement.declareGoodsAdvertisement}">
                                <td th:case="0">是</td>
                                <td th:case="1">否</td>
                            </div>
                            <td th:text="${advertisement.age}"></td>
                            <div th:switch="${advertisement.sex}">
                                <td th:case="1">男</td>
                                <td th:case="0">女</td>
                                <td th:case="2">不限</td>
                            </div>
                            <td><a th:text="${advertisement.videoName}" target="_blank" th:href="@{${advertisement.topVideoURL}}"></a></td>
                            <td><a th:text="${advertisement.imageName}" target="_blank" th:href="@{${advertisement.bottomImageURL}}"></a></td>
                            <div th:switch="${advertisement.advertisementStatus}">
                                <td th:case="0">待审核</td>
                                <td th:case="1">上线</td>
                                <td th:case="2">下线</td>
                            </div>
                            <td class="btn-group">
                                <!--<div th:switch="${advertisement.advertisementStatus}">
                                        <a class="btn-online" th:case="0">上线</a>
                                        <a class="btn-offline" th:case="1">下线</a>
                                        <a class="btn-online" th:case="2">上线</a>
                                </div>-->
                                <a  th:switch="${advertisement.advertisementStatus}">
                                    <span class="btn-online" th:case="0">上线</span>
                                    <span class="btn-offline" th:case="1">下线</span>
                                    <span class="btn-online" th:case="2">上线</span>
                                </a>
                                <a class="btn-detail">编辑</a>
                                <a class="btn-del">删除</a>
                                <a class="btn-monitor">监播报告</a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <div class="table-info z-pat z-fl">
                        广告总数：<p class="total margin" th:text="${total}"></p>
                    </div>
                    <!-- 分页 -->
                    <div class="app-card-body">
                        <div class="pagination z-pat z-fr"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>


<!--新增/编辑-->
<div class=" popup-default z-popup z-fixed z-df z-flex-cc z-hide">
    <div class="bg" data-popup-close=""></div>
    <div class="section popup-add z-hide">
        <div class="title">新增广告</div>
        <div class="content" id="departmentForm">
            <form>
                <div class="form-item row" style="display: none">
                    <div class="label">
                        <label>ID</label>
                    </div>
                    <div class="body">
                        <input type="hidden" name="advertisementId" class="advertisementId">
                    </div>
                </div>
                <div class="form-item row">
                    <div class="label">
                        <label>广告状态</label>
                    </div>
                    <div class="body">
                        <label style="margin-right:10px;">
                            <select name="advertisementStatus">
                                <option value="">---请选择---</option>
                                <option  th:each="advertisementStatus: ${advertisementStatusMap}" th:value="${advertisementStatus.key}" th:text="${advertisementStatus.value}"/>
                            </select>
                        </label>
                    </div>
                </div>
                <div class="form-item row">
                    <div class="label">
                        <label>是否是品宣广告</label>
                    </div>
                    <div class="body">
                        <label style="margin-right:10px;">
                            <input class="input" type="radio" name="declareGoodsAdvertisement" value="1" th:text="否"
                                   style="margin-right:5px;">
                        </label>
                        <label style="margin-right:10px;">
                            <input class="input" type="radio" name="declareGoodsAdvertisement" value="0" th:text="是"
                                   style="margin-right:5px;">
                        </label>
                    </div>
                </div>
                <div class="form-item row">
                    <div class="label">
                        <label>选择广告主</label>
                    </div>
                    <div class="body">
                        <label style="margin-right:10px;">
                            <select name="advertiserId">
                            </select>
                        </label>
                    </div>
                </div>
                <div class="form-item row">
                    <div class="label">
                        <label>广告名称</label>
                    </div>
                    <div class="body">
                        <input type="text" placeholder="请输入广告名称" class="advertisementName"
                               name="advertisementName" data-name="广告名称" data-rule="required,length" minlength="1"
                               maxlength="32">

                    </div>
                </div>
                <div class="form-item row">
                    <div class="label">
                        <label>广告品牌</label>
                    </div>
                    <div class="body">
                        <input type="text" placeholder="请输入广告品牌" class="advertisementBrand"
                               name="advertisementBrand" data-name="广告品牌" data-rule="required,length" minlength="1"
                               maxlength="32">

                    </div>
                </div>
                <div class="form-item row" style=" align-items: start; ">
                    <div class="label">
                        <label>年龄</label>
                    </div>
                    <div class="body">
                        <div class="age multi-select" data-key="value">
                            <div class="multi-select-selected"></div>
                            <select></select>
                        </div>
                    </div>
                </div>
                <div class="form-item row">
                    <div class="label">
                        <label>性别</label>
                    </div>
                    <div class="body">
                        <label style="margin-right:10px;">
                            <select name="sex">
                                <option value="">---请选择---</option>
                                <option th:each="sexs: ${sexMap}" th:value="${sexs.key}" th:text="${sexs.value}"/>
                            </select>
                        </label>

                    </div>
                </div>
                <div class="form-item row">
                    <div class="label">
                        <label>上屏视频(avi)</label>
                    </div>
                    <div class="body" style="min-width: 350px;">
                        <div class="upload upload-file z-mab" data-input-name="url" data-limit="1"
                             th:attr="data-url=@{/file/uploadVideo}" data-fieldname="files"
                             data-upload-success="uploadVideoSuccess">
                            <div class="upload-list upload-list-text"></div>
                            <div class="upload-tips">只能上传avi格式视频</div>
                            <div class="upload-error"></div>
                            <div class="input-opacity">
                                <input type="file" class="input" accept=".avi" style="max-width: 90px;">
                                <input type="hidden" name="topVideoURL">
                                <input type="hidden" name="videoMd5">
                                <input type="hidden" name="videoName">
                                <a class="z-btn z-default"><i class="fa fa-upload"></i> 上传</a>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-item row">
                    <div class="label">
                        <label>下屏图片(jpg)</label>
                    </div>
                    <div class="body">
                        <div class="upload upload-image z-mab" data-input-name="url" data-limit="1"
                             th:attr="data-url=@{/file/uploadImage}" data-fieldname="files"
                             data-upload-success="uploadImageSuccess">
                            <div class="upload-list upload-list-image">
                            </div>
                            <div class="upload-tips">只能上传jpg格式图片</div>
                            <div class="upload-error"></div>
                            <div class="upload-loading">
                                <i class="fa fa-cog fa-spin"></i>图片上传中...
                            </div>
                            <div class="input-opacity">
                                <input type="file" class="input" accept="image/jpg" multiple="multiple">
                                <input type="hidden" name="bottomImageURL">
                                <input type="hidden" name="imageMd5">
                                <input type="hidden" name="imageName">
                                <a class="z-btn z-default"><i class="fa fa-upload"></i> 上传</a>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <div class="z-btn-group">
                <a class="btn-submit z-btn z-primary user-comfirm">确定</a>
                <a class="z-btn z-default" data-popup-close="">取消</a>
            </div>
        </div>
    </div>
    <div class="popup-detail section z-hide"></div>
</div>

<script th:src="@{/lib/jquery.min.js}"></script>
<script th:src="@{/lib/layer-v3.1.1/layer/layer.js}"></script>
<script th:src="@{/js/popup.js}"></script>
<script th:src="@{/js/form.js}"></script>
<script th:src="@{/js/admin/app.js}"></script>
<script th:src="@{/js/pagination.js}"></script>
<script th:src="@{/js/admin-upload.js}"></script>
<script type="text/javascript" th:inline="javascript">
    var ageArr=[[${ageRangeList}]];
    // var ageRange=[[${ageRange}]];

    $(function () {
        eventEmit();

        $('.popup-detail').html($('.popup-add').html()).find('.title').text('修改');

        setAge('.popup-add .age', ageArr, "");
        MultiSelect();
    })

    //获取context path
    var context = $("meta[name='ctx']").attr("content") || '';
    //当前页
    var pageNum = [[${pageNum}]];
    //没有条数
    var pageSize = [[${pageSize}]];
    //总数
    var total = [[${total}]];
    var queryURL = "/advertisement/list?pageSize=" + pageSize;
    if (context) {
        queryURL = context + queryURL;
    }
    var queryArg=queryURL;
    var queryURL = appendQueryParameter(queryURL);
    var pagination = new Pagination(".pagination", {
        pageIndex: pageNum, // 当前页数
        pageSize: pageSize, // 每页数量
        count: total, // 总条数
        maxButtonCount: 5, // 分页按钮数量(可选)
        // 分页切换事件
        onPageChanged: function (pageIndex) {
            var queryURL = appendQueryParameter(queryArg);
            window.location.href = queryURL + "&pageNum=" + pageIndex;
        }
    })

    //拼接分页查询参数
    function appendQueryParameter(queryURL) {
        //广告主
        var advertiserNameQuery = $("#advertiserNameQuery").val();
        if (advertiserNameQuery) {
            queryURL = queryURL + "&advertiserName=" + advertiserNameQuery;
        }
        //广告状态
        var advertisementStatusQuery = $("#advertisementStatusQuery").val();
        if (advertisementStatusQuery) {
            queryURL = queryURL + "&advertisementStatus=" + advertisementStatusQuery;
        }
        //年龄
        var sexQuery = $("#sexQuery").val();
        if (sexQuery) {
            queryURL = queryURL + "&sex=" + sexQuery;
        }
        //广告名称
        var advertisementNameQuery = $("#advertisementNameQuery").val();
        if (advertisementNameQuery) {
            queryURL = queryURL + "&advertisementName=" + advertisementNameQuery;
        }
        //年龄
        var ageQuery = $("#ageQuery").val();
        if (ageQuery) {
            queryURL = queryURL + "&age=" + ageQuery;
        }
        return queryURL;
    }


    // 设置性别数据
    function setAge(selector, ageArr, ageRange) {
        var options = ['<option>请选择</option>'];
        var selected = [];

        for (var i = 0; i < ageArr.length; i++) {
            var item = ageArr[i];
            options.push(`<option data-value="${item}">${item}</option>`)
        }

        if(ageRange){
            ageRange = (ageRange || '').split(',');

            for (var i = 0; i < ageRange.length; i++) {
                var item = ageRange[i];
                selected.push(`
                    <div data-value="${item}" class="multi-select-item">
                        <span class="name">${item}</span>
                        <span class="close fa fa-close"></span>
                    </div>
                `)
            }
            $(selector).find('.multi-select-selected').html(selected.join(''));
        }

        $(selector).find('select').html(options.join(''));

    }

    // 多选选择器
    function MultiSelect() {
        $('.multi-select').on('change', 'select', function() {
            var $parent = $(this).parent('.multi-select');
            var option = $parent.data();
            // 唯一值排重
            var key = option.key || 'id';
            var $selected = $parent.children('.multi-select-selected');
            var item = $(this).find('option:selected')[0].dataset;

            var repeat;
            $selected.find('.multi-select-item').each(function(index, el) {
                if ($(this).data(key) == item[key]){
                    popup.tips('已存在，请勿重复添加');
                    return repeat = true;
                }
            });

            if (!repeat) {
                var html = '';

                html = `
                        <div data-value="${item.value}" class="multi-select-item">
                            <span class="name">${item.value}</span>
                            <span class="close fa fa-close"></span>
                        </div>
                    `;

                $selected.append(html);
            }
        })

        // 多选下拉菜单 - 删除
        $(document).on('click', '.multi-select-item .close', function(e) {
            $(this).parent().remove();
        })
    }


    function  listAdvertiserSelect(advertiserId,$select,callback) {
        //请求广告主
        $.ajax({
            type: "POST",
            url: context + "/advertiser/listAdvertiserSelect",
            success: function (obj) {
                var code = obj.code;
                if (code == 0) {
                    var result = obj.data;
                    var selectArr = ['<option value="">---请选择---</option>']
                    for (var i = 0 ; i<result.length;i++){
                        var checked = '';
                        if(advertiserId == result[i].advertiserId){
                            checked = 'checked';
                        }

                        selectArr.push(' <option value="'+result[i].advertiserId+'" '+checked+'>'+result[i].advertiserName+'</option>')
                    }

                    $select.html(selectArr.join(''));

                    callback(obj.data)
                }
            }
        })
    }

    function eventEmit() {
        // 新增 - 弹窗打开
        $('.btn-add').click(function () {

            listAdvertiserSelect(null,$('.popup-add [name="advertiserId"]'),function () {

                $('.popup-add').formLoad({
                    // advertisementStatus: '',
                    declareGoodsAdvertisement: '',
                    advertiserId: '',
                    advertisementName: '',
                    advertisementBrand: '',
                    age: '',
                    sex: '',
                    topVideoURL: '',
                    videoMd5: '',
                    videoName: '',
                    bottomImageURL: '',
                    imageMd5: '',
                    imageName: ''
                })

                popup.open('.popup-add')
            })

        })

        // 修改 - 弹窗打开
        $('.btn-detail').click(function () {
                var data = $(this).parents('tr')[0].dataset;
                var advertiserId = data.advertiserid;
                listAdvertiserSelect(advertiserId,$('.popup-detail [name="advertiserId"]'),function () {
                //取值
                var advertisementId = data["id"];
                var advertisementStatus = data["advertisementstatus"];
                var declareGoodsAdvertisement = data["declaregoodsadvertisement"];
                var advertisementName = data["advertisementname"];
                var advertisementBrand = data["advertisementbrand"];
                var age = data["age"];
                var sex = data["sex"];
                var topVideoURL = data["topvideourl"];
                var videoName = data["videoname"];
                var videoMd5 = data["videomd5"];
                var bottomImageURL = data["bottomimageurl"];
                var imageName = data["imagename"];
                var imageMd5 = data["imagemd5"];



                $('.popup-detail').formLoad({
                    advertisementId:advertisementId,
                    advertisementStatus: advertisementStatus,
                    declareGoodsAdvertisement: declareGoodsAdvertisement,
                    advertisementName: advertisementName,
                    advertisementBrand: advertisementBrand,
                    advertiserId:advertiserId,
                    age: age,
                    sex: sex,
                    topVideoURL: topVideoURL,
                    videoName: videoName,
                    videoMd5: videoMd5,
                    bottomImageURL: bottomImageURL,
                    imageName: imageName,
                    imageMd5: imageMd5
                });

                console.log('ageRange',age)

                setAge('.popup-detail .age', ageArr, age);

                popup.open('.popup-detail');
            })
        })
    }
    // 从URL加载搜索数据
    $(".filter").formLoad(App.query);

    // 上传视频成功回调
    function uploadVideoSuccess(data) {
        //赋值图片的URL和md5值
        var fileData = data[0];
        $('[name="topVideoURL"]').val(fileData["url"]);
        $('[name="videoMd5"]').val(fileData["md5"]);
        $('[name="videoName"]').val(fileData["name"]);
    }
    // 上传图片成功回调
    function uploadImageSuccess(data) {
        //赋值图片的URL和md5值
        var fileData = data[0];
        $('[name="bottomImageURL"]').val(fileData["url"]);
        $('[name="imageMd5"]').val(fileData["md5"]);
        $('[name="imageName"]').val(fileData["name"]);
    }

    // 新增 - 弹窗保存
    var form = $(".popup-add form").form({
        submitSelector: ".popup-add .btn-submit",
        msg: function (msg) {
            popup.tipsTop(msg, 'warning');
        },
        submit: function () {
            var data = {};
            $.each($(".popup-add form").serializeArray(), function (index, field) {
                if (data[field.name]) {
                    data[field.name] += "," + field.value;
                } else {
                    data[field.name] = field.value;
                }
            })

            var age = [];
            $('.popup-add .age .multi-select-item').each(function () {
                age.push($(this).data('value'));
            })

            data.age = age.join(',');

            $.ajax({
                type: "POST",
                url: context + "/advertisement/save",
                data: data,
                success: function (obj) {
                    var code = obj.code;
                    if (code == 0) {
                        popup.tipsTop('新增广告成功', 'success');
                        setTimeout(function (args) {
                            //跳转到广告列表
                            window.location.href = context + "/advertisement/list";
                        }, 100);
                    } else {
                        popup.tipsTop(obj.msg, 'warning');
                    }
                }
            })
        }
    })


    // 修改 - 弹窗确定
    var form = $(".popup-detail form").form({
        submitSelector: ".popup-detail .btn-submit",
        msg: function (msg) {
            popup.tipsTop(msg, 'warning');
        },
        submit: function () {
            var data = {};
            $.each($(".popup-detail form").serializeArray(), function (index, field) {
                if (data[field.name]) {
                    data[field.name] += "," + field.value;
                } else {
                    data[field.name] = field.value;
                }
            })

            var age = [];
            $('.popup-detail .age .multi-select-item').each(function () {
                console.log('dasdasda',$(this).data('value'))
                age.push($(this).data('value'));
            })


            data.age = age.join(',');

            //修改
            $.ajax({
                type: "POST",
                url: context + "/advertisement/update",
                data: data,
                success: function (obj) {
                    var code = obj.code;
                    if (code == 0) {
                        popup.tipsTop('修改广告成功', 'success');
                        setTimeout(function (args) {
                            //跳转到广告列表
                            window.location.href = context + "/advertisement/list";
                        }, 1000);
                    } else {
                        popup.tipsTop(obj.msg, 'warning');
                    }
                }
            })
        }
    })

    // 删除 - 弹窗确定
    $('.btn-del').click(function () {
        if (confirm("确认删除")) {
            var data = $(this).parents('tr')[0].dataset;
            //取值
            var advertisementid = data["id"];

            //修改
            $.ajax({
                type: "POST",
                url: context + "/advertisement/delete",
                data: {advertisementId: advertisementid},
                success: function (obj) {
                    var code = obj.code;
                    if (code == 0) {
                        popup.tipsTop('删除广告成功', 'success');
                        setTimeout(function (args) {
                            //跳转到广告列表
                            window.location.href = context + "/advertisement/list";
                        }, 1000);
                    } else {
                        popup.tipsTop(obj.msg, 'warning');
                    }
                }
            })
        }
    })

    //上线
    $('.btn-online').click(function () {
        if (confirm("确认上线")) {
            var data = $(this).parents('tr')[0].dataset;
            //取值
            var advertisementid = data["id"];
            var advertisementName = data["advertisementname"];
            //上线状态为1
            var advertisementStatus = 1;
            //修改
            $.ajax({
                type: "POST",
                url: context + "/advertisement/updateAdvertisementStatus",
                data: {
                    advertisementId: advertisementid,
                    advertisementName: advertisementName,
                    advertisementStatus: advertisementStatus
                },
                success: function (obj) {
                    var code = obj.code;
                    if (code == 0) {
                        popup.tipsTop('上线成功', 'success');
                        setTimeout(function (args) {
                            //跳转到广告列表
                            window.location.href = context + "/advertisement/list";
                        }, 1000);
                    } else {
                        popup.tipsTop(obj.msg, 'warning');
                    }
                }
            })
        }
    })

    //下线
    $('.btn-offline').click(function () {
        if (confirm("确认下线")) {
            var data = $(this).parents('tr')[0].dataset;
            //取值
            var advertisementid = data["id"];
            var advertisementName = data["advertisementname"];
            //上线状态为1
            var advertisementStatus = 2;
            //修改
            $.ajax({
                type: "POST",
                url: context + "/advertisement/updateAdvertisementStatus",
                data: {
                    advertisementId: advertisementid,
                    advertisementName: advertisementName,
                    advertisementStatus: advertisementStatus
                },
                success: function (obj) {
                    var code = obj.code;
                    if (code == 0) {
                        popup.tipsTop('上线成功', 'success');
                        setTimeout(function (args) {
                            //跳转到广告列表
                            window.location.href = context + "/advertisement/list";
                        }, 1000);
                    } else {
                        popup.tipsTop(obj.msg, 'warning');
                    }
                }
            })
        }
    })

    //监播报告
    $('.btn-monitor').click(function () {
        var data = $(this).parents('tr')[0].dataset;
        //广告名称
        var advertisementName = data["advertisementname"];
        //开始时间为前30天的数据
        var startTime = getPastFutureTime(-29);
        //结束时间
        var endTime = getNowTime();
        var url = "/dataReport/goTotalData";
        if (!advertisementName || advertisementName == '' || advertisementName.length == 0) {
            popup.tipsTop("广告名称不能为空", 'warning');
            return;
        }
        if (context) {
            url = context + url;
        }
        window.location.href = url + "?advertisementName=" + advertisementName + "&startTime=" + startTime + "&endTime=" + endTime;
    })

    /**
     * 获取N天前后日期的方法（正式表示后面的日期，负数表示前面的日期）（返回日期格式为yyyy-MM-dd）
     */
    function getPastFutureTime(dayCount) {
        var date = new Date();
        //获取dayCount天后的日期
        date.setDate(date.getDate() + dayCount);
        var y = date.getFullYear();
        var m = (date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1);//获取当前月份的日期，不足10补0
        var d = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();//获取当前几号，不足10补0
        return y+"-"+m+"-"+d;
    }

    function getNowTime() {
        var date = new Date();
        var year = date.getFullYear();
        var month = (date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1);//获取当前月份的日期，不足10补0
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();//获取当前几号，不足10补0
        return year + "-" + month + "-" + day;
    }

</script>
</body>

</html>